@(active: String,
  repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
  id: Option[String] = None,
  info: Option[Any] = None,
  error: Option[Any] = None)(body: Html)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers

@menuitem(path: String, name: String, label: String, icon: String, count: Int = 0) = {
  <li class = "menu-item-hover @if(active == name){active}">
    @if(path.startsWith("http")){
      <a href="@path" target="_blank">
        <i class="menu-icon octicon octicon-@icon"></i>
        <span>@label</span>
        @if(count > 0){
          <span class="pull-right-container"><span class="label label-primary pull-right-container">@count</span></span>
        }
      </a>
    } else {
      <a href="@helpers.url(repository)@path">
        <i class="menu-icon octicon octicon-@icon"></i>
        <span>@label</span>
        @if(count > 0) {
          <span class="pull-right-container"><span class="label label-primary pull-right">@count</span></span>
        }
      </a>
    }
  </li>
}

<div class="main-sidebar">
  <div class="sidebar">
    <ul class="sidebar-menu">
      @menuitem("", "files", "Files", "code")
      @if(repository.branchList.nonEmpty) {
        @menuitem("/branches", "branches", "Branches", "git-branch", repository.branchList.length)
      }
      @menuitem("/releases", "releases", "Releases", "tag", repository.tags.length)
      @if(repository.repository.options.issuesOption != "DISABLE") {
        @menuitem("/issues", "issues", "Issues", "issue-opened", repository.issueCount)
        @menuitem("/pulls", "pulls", "Pull requests", "git-pull-request", repository.pullCount)
        @menuitem("/issues/labels", "labels", "Labels", "tag")
        @menuitem("/issues/priorities", "priorities", "Priorities", "flame")
        @menuitem("/issues/milestones", "milestones", "Milestones", "milestone", repository.milestoneCount)
      } else {
        @repository.repository.options.externalIssuesUrl.map { externalIssuesUrl =>
          @menuitem(externalIssuesUrl, "issues", "Issues", "issue-opened")
        }
      }
      @if(repository.repository.options.wikiOption != "DISABLE") {
        @menuitem("/wiki", "wiki", "Wiki", "book")
      } else {
        @repository.repository.options.externalWikiUrl.map { externalWikiUrl =>
          @menuitem(externalWikiUrl, "wiki", "Wiki", "book")
        }
      }
      @gitbucket.core.plugin.PluginRegistry().getRepositoryMenus.map { menu =>
        @menu(repository, context).map { link =>
          @menuitem(link.path, link.id, link.label, link.icon.getOrElse("ruby"))
        }
      }
      @if(context.loginAccount.isDefined && (context.loginAccount.get.isAdmin || repository.managers.contains(context.loginAccount.get.userName))){
        @menuitem("/settings", "settings", "Settings", "gear")
      }
    </ul>
  </div>
</div>
<div class="content-wrapper">
  <div class="content body clearfix">
    <div class="headbar">
      <div class="container">
        @gitbucket.core.helper.html.information(info)
        @gitbucket.core.helper.html.error(error)
        <div class="head">
          <div class="pull-right">
            @gitbucket.core.plugin.PluginRegistry().getRepositoryHeaders.map { repositoryHeaderComponent =>
              @repositoryHeaderComponent(repository, context)
            }
            @if(repository.repository.options.allowFork && (context.settings.basicBehavior.repositoryOperation.fork || context.loginAccount.map(_.isAdmin).getOrElse(false))) {
              @if(context.loginAccount.isEmpty){
                <a class="btn btn-default btn-sm" href="@context.path/signin?redirect=@helpers.urlEncode(s"${context.path}/${repository.owner}/${repository.name}")">
                  <span class="strong"><i class="octicon octicon-repo-forked"></i>Fork</span><span class="muted">: @repository.forkedCount</span>
                </a>
              } else {
                <a class="btn btn-default btn-sm" href="@context.path/@repository.owner/@repository.name/fork" rel="facebox">
                  <span class="strong"><i class="octicon octicon-repo-forked"></i>Fork</span><span class="muted">: @repository.forkedCount</span>
                </a>
              }
            }
            <form id="fork-form" method="post" action="@context.path/@repository.owner/@repository.name/fork" style="display: none;">
              <input type="hidden" name="account" value="@context.loginAccount.map(_.userName)"/>
            </form>
          </div>
          @gitbucket.core.helper.html.repositoryicon(repository, true)
          <a href="@helpers.url(repository.owner)">@repository.owner</a> / <a href="@helpers.url(repository)" class="strong">@repository.name</a>

          @defining(repository.repository){ x =>
            @if(repository.repository.originRepositoryName.isDefined){
              <div class="forked">
                forked from <a href="@context.path/@x.parentUserName/@x.parentRepositoryName">@x.parentUserName/@x.parentRepositoryName</a>
              </div>
            }
          }
        </div>
      </div>
    </div>
    @body
  </div>
</div>
<script>
$(function(){
  $('a[rel*=facebox]').facebox({
    'loadingImage': '@helpers.assets("/vendors/facebox/loading.gif")',
    'closeImage': '@helpers.assets("/vendors/facebox/closelabel.png")'
  });

  $(document).on("click", ".js-fork-owner-select-target", function() {
    var account = $(this).text().replace("@@", "");
    $("#account").val(account);
    $("#fork").submit();
  });
});
</script>


